console.log(location.href);

const searchStr = location.href
const id = searchStr.split('=')[1];
console.log(id);
axios.get('/students/' + id)
    .then(res => {
        console.log(res.data);
        const resData = res.data;
        document.querySelector('#name').value = resData.name
        document.querySelector('#age').value = resData.age
        document.querySelector('#gender').value = resData.gender
        document.querySelector('#province').value = resData.province
        document.querySelector('#city').value = resData.city
        document.querySelector('#area').value = resData.area
        document.querySelector('#group').value = resData.group
        document.querySelector('#hope_salary').value = resData.hope_salary
        document.querySelector('#salary').value = resData.salary

        // 提交
        document.querySelector('button').addEventListener('click', function (e) {
            e.preventDefault()// 阻止默认行为
            const form = document.querySelector('#studentForm')
            let data = serialize(form, { hash: true, Empty: true })
            data.age = parseInt(data.age)
            data.gender = parseInt(data.gender)
            data.hope_salary = parseInt(data.hope_salary)
            data.salary = parseInt(data.salary)
            data.group = parseInt(data.group)
            console.log(data);
            modifyStudent(id, data)

        })

    })


// 修改接口
async function modifyStudent(id, body) {
// console.log('id and body -->',id, body);
    await axios.put('/students/'+id, body)
        .then(res => {
            pxmu.success('修改成功')
            console.log(res);           
            setTimeout(() => {
                location.href = './student.html'
            }, 1000);

        })
}